package com.hivekion.system.controller;

import com.hivekion.common.annotation.AutoLog;
import com.hivekion.common.entity.PagedResultVo;
import com.hivekion.common.entity.SearchInputVo;
import com.hivekion.common.entity.SelectOption;
import com.hivekion.common.enums.OperationTypeEnum;
import com.hivekion.system.domain.vo.*;
import com.hivekion.system.service.ISysRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/system/role")
public class SysRoleController {
      @Autowired
      ISysRoleService service;

      @GetMapping("/getInfo")
      @AutoLog(value = "角色查询", operationType = OperationTypeEnum.SELECT, module = "系统管理/角色管理")
      public SysRoleModelVo getInfo(String roleId) {
	    return service.getInfo(roleId);
      }

      @PostMapping("/checkRoleNameUnique")
      public boolean checkRoleNameUnique(String roleName, String roleId) {
	    if (!service.checkRoleNameUnique(roleId, roleName)) {
		  return true;
	    }
	    return false;
      }

      @PostMapping("/add")
      @PreAuthorize("@Permission.hasPermi('pro:sys:role:add')")
      @AutoLog(value = "新增角色信息", operationType = OperationTypeEnum.INSERT, module = "系统管理/角色管理")
      public boolean add(@RequestBody SysRoleCreateInputVo inputVo) {
	    return service.add(inputVo);
      }

      @PutMapping("/edit")
      @PreAuthorize("@Permission.hasPermi('pro:sys:role:edit')")
      @AutoLog(value = "变更角色信息", operationType = OperationTypeEnum.UPDATE, module = "系统管理/角色管理")
      public boolean edit(@RequestBody SysRoleUpdateInputVo inputVo) {
	    return service.edit(inputVo);
      }

      @DeleteMapping("/remove")
      @PreAuthorize("@Permission.hasPermi('pro:sys:role:remove')")
      @AutoLog(value = "删除角色信息", operationType = OperationTypeEnum.DELETE, module = "系统管理/角色管理")
      public boolean remove(String roleId) {
	    return service.remove(roleId);
      }

      @PostMapping("/changeStatus")
      @PreAuthorize("@Permission.hasPermi('pro:sys:role:edit')")
      @AutoLog(value = "修改角色状态", operationType = OperationTypeEnum.UPDATE, module = "系统管理/角色管理")
      public boolean changeStatus(String roleId, Integer status) {
	    return service.changeStatus(roleId, status);
      }

      @GetMapping("/getList")
      public PagedResultVo<SysRoleModelVo> getList(SearchInputVo inputVo) {
	    return service.getList(inputVo);
      }

      @GetMapping("/getRoleOptions")
      public List<SelectOption> getRoleOptions() {
	    return service.getRoleOptions();
      }

      @PostMapping("/setPermissions")
      @PreAuthorize("@Permission.hasPermi('pro:sys:role:permission')")
      @AutoLog(value = "设置角色权限信息", operationType = OperationTypeEnum.UPDATE, module = "系统管理/角色管理")
      public boolean setPermissions(@RequestBody SetRolePermissionVo vo) {
	    return service.setPermissions(vo);
      }

      @GetMapping("/getPermissions")
      public SysRolePermissionsModelVo getPermissions(String roleId) {
	    return service.getPermissions(roleId);
      }
}
